package com.ctrip.cap.appium;

import io.appium.java_client.android.AndroidDriver;

import java.net.URL;

import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.Capabilities;

import com.ctrip.cap.device.Device;

/**
 * Swipe Action Adaptor for Selendroid Mode 进一步简化代码
 * 
 * @author ltyao
 *
 */
public class DeviceSwipeDriver extends AndroidDriver {

	private Device device;

	public DeviceSwipeDriver(URL remoteAddress, Capabilities desiredCapabilities) {
		super(remoteAddress, desiredCapabilities);
	}

	public DeviceSwipeDriver(URL remoteAddress,
			Capabilities desiredCapabilities, Device device) {
		super(remoteAddress, desiredCapabilities);
		this.device = device;
	}

	@Override
	public void swipe(int startx, int starty, int endx, int endy, int duration) {
		String automationName = (String) getCapabilities().getCapability(
				"automationName");
		if (StringUtils.equalsIgnoreCase(automationName, "Selendroid")
				&& device != null) {
			device.swipe(startx, starty, endx, endy);
		} else {
			super.swipe(startx, starty, endx, endy, duration);
		}

	}

}
